# -*- coding:utf-8 -*-
from baidu_hot import get_baidu_hot
from toutiao_hot import get_toutiao_hot
from weibo_hot import get_weibo_hot
from zhihu_hot import get_zhihu_hot
from csdn_hot import get_csdn_hot
import time
import logging

LOG_FORMAT = "%(levelname)s %(asctime)s - %(message)s"
logging.basicConfig(filename="hot_news.log", filemode="a", level=logging.INFO, format=LOG_FORMAT)
logger = logging.getLogger()
# print("欢迎回来！请输入对应数字浏览热搜")
# while True:
#     user_input = input("1-baidu；2-toutiao；3-weibo；4-zhihu；5-CSDN；q/Q-退出；请输入：")
#     if user_input == '1':
#         get_baidu_hot()
#     elif user_input == '2':
#         get_toutiao_hot()
#     elif user_input == '3':
#         get_weibo_hot()
#     elif user_input == '4':
#         get_zhihu_hot()
#     elif user_input == '5':
#         get_csdn_hot()
#     elif user_input == 'q' or user_input == 'Q':
#         break
#     else:
#         print("用户非法输入，3s后刷新，重新选择操作")
#         time.sleep(3)
# print("退出应用成功，期待再次光临")

sec = 5
while True:
    baidu_hots = get_baidu_hot()
    for baidu_hot in baidu_hots:
        time.sleep(sec)
        logger.info(baidu_hot['text'])

    # print(baidu_hots)
    toutiao_hots = get_toutiao_hot()
    for toutiao_hot in toutiao_hots:
        time.sleep(sec)
        logger.info(toutiao_hot['title'])
    # print(toutiao_hots)
    weibo_hots = get_weibo_hot()
    for weibo_hot in weibo_hots:
        time.sleep(sec)
        logger.info(weibo_hot['title'])
    # print(weibo_hots)
    zhihu_hots = get_zhihu_hot()
    for zhihu_hot in zhihu_hots:
        time.sleep(sec)
        logger.info(zhihu_hot['title'])
    # print(zhihu_hots)

    # csdn_hots = get_csdn_hot()
    # for csdn_hot in csdn_hots:
    #     time.sleep(sec)
    #     logger.info(csdn_hot['title'])
